var express = require('express');
var router = express.Router();
var https = require('https');
var http = require('http');

// 跨域请求


router.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
});
//list页面请求的数据
router.get('/list',function(req,res){
    https.get('https://mainsite-restapi.ele.me/shopping/restaurants?latitude=22.54286&longitude=114.059563&keyword=&offset=0&limit=20&extras[]=activities&restaurant_category_ids[]=209&restaurant_category_ids[]=211&restaurant_category_ids[]=212&restaurant_category_ids[]=213&restaurant_category_ids[]=214&restaurant_category_ids[]=215&restaurant_category_ids[]=216&restaurant_category_ids[]=217&restaurant_category_ids[]=218&restaurant_category_ids[]=219&restaurant_category_ids[]=221&restaurant_category_ids[]=222&restaurant_category_ids[]=223&restaurant_category_ids[]=224&restaurant_category_ids[]=225&restaurant_category_ids[]=226&restaurant_category_ids[]=227&restaurant_category_ids[]=228&restaurant_category_ids[]=229&restaurant_category_ids[]=230&restaurant_category_ids[]=231&restaurant_category_ids[]=232&restaurant_category_ids[]=234&restaurant_category_ids[]=235&restaurant_category_ids[]=236&restaurant_category_ids[]=237&restaurant_category_ids[]=238&restaurant_category_ids[]=263&restaurant_category_ids[]=264&restaurant_category_ids[]=265&restaurant_category_ids[]=266&restaurant_category_ids[]=267&restaurant_category_ids[]=268&restaurant_category_ids[]=269',function(response){
         var data='';
        response.on('data',function(chunk){
            data+=chunk;
        })

        response.on('end',function(){
            res.send(data)
        })
    })
})
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('detail',function(req,res){

  
  http.get('http://catdot.dianping.com/broker-service/api/single?v=1&ts=1501674687129&tu=/ajax/v8/poi/food?_token=eJx9jUFLw0AQhf/LHLy4JDvZ7G4SCFLtwaoJKmmhFA/bGtpNu6kkU7QV/7tbCBQvwsD35vFm3jd0k3fIkHOOnAH1XkuOSscqUanUDFZ/PI2IDJbdbAzZQmjJlNJvZ+PV7xfjoqLYzzkx8QHYEH1kYWiDT2OdsYGrLR1MG6z2LuzqnsyhMy2FQqdKJimKSCgtFbB/Dzd7V9/sDOVRFMgE01hd7dp1jigC/0ZwDb7fVb7fczvQDKSBvV23kEH98FU99tflU9I8N0Va9NU0otPLiZYjXo7nx7IpRDkr7kb38+MtbnP4+QX8DFtU&d=97&hs=200',function(response){
      var data = '';

      response.on('data',function(chunk){
        data += chunk;
      })
      response.on('end',function(){
          res.send(data)

      })
  })
})

router.get('page',function(req,res){

  
  http.get('http://127.0.0.1:8080/',function(response){
      var data = '';

      response.on('data',function(chunk){
        data += chunk;
      })
      response.on('end',function(){
          res.send(data)

      })
  })
})


module.exports = router;
